



DELETE FROM erp_mli2.pcp_planindicval
WHERE  PLANCPTE_COD  ='PREV_AN'  AND INDIC_COD ='VC' ;




INSERT INTO  erp_mli2.pcp_planindicval (
/*SELECT plancpte_cod, cpte_cod, combsto_id, planindic_cod, indic_cod, periodeplan_val, planindicval_rang,Count(*) FROM (*/
SELECT  'PREV_AN' PLANCPTE_COD,
       Decode(ligne_cod,'LOC','LOCATION','IMI','GRANDCOMPT','DISTRI') CPTE_COD,
       NULL FOURNISSEUR_COD,
       NULL OF_NO,
       outils_mli2.enreg_id.nextval ENREG_ID,
       NULL DEBCYCLE_DAT,
       NULL FINCYCLE_DAT,
       p.aaaa PERIODEPLAN_VAL,
       'PREV_AN' PLANINDIC_COD,
       'VC' INDIC_COD,
       COMBSTO_REF COMBSTO_ID,
       1 PLANINDICVAL_RANG,
       qtep PLANINDICVAL_QTE,
       'reprise' PLANINDICVAL_LIB,
       NULL PLANPERE_COD
from  uv_zp_preventesa p,erp_mli2.art_refe r , temp_conv_rgp_combstoref t
WHERE  p.prodbase=r.refe_cod || '' || r.refe_ind
  AND t.CLERGP=p.numspecif AND IS_COMPREF ='COMPREF'
  AND qtep IS NOT null
  AND p.aaaa+0>2003 /*)
GROUP BY plancpte_cod, cpte_cod, combsto_id, planindic_cod, indic_cod, periodeplan_val, planindicval_rang
HAVING Count(1)>1
ORDER BY PERIODEPLAN_VAL*/ )  ;

/*
SELECT * FROM  temp_conv_rgp_combstoref

SELECT PLANCPTE_COD, CPTE_COD, FOURNISSEUR_COD, OF_NO, ENREG_ID, DEBCYCLE_DAT, FINCYCLE_DAT, PERIODEPLAN_VAL, PLANINDIC_COD, INDIC_COD, COMBSTO_ID, PLANINDICVAL_RANG, PLANINDICVAL_QTE, PLANINDICVAL_LIB, PLANPERE_COD
FROM erp_mli2.pcp_planindicval
WHERE  PLANCPTE_COD  ='PREV_AN'  AND INDIC_COD ='VC'
*/